﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace QLHH
{
    class HoaDonDAL
    {
        public HoaDonDAL()
        {

        }
        public DataTable DocDanhSachHoaDon()
        {
            SqlConnection conn = SQLDatabase.Conection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from hanghoa inner join hoadon on hoadon.mahang=hanghoa.mahang", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            return dt;
        }
        public void XoaHoaDon(string sohd)
        {
            SqlConnection conn = SQLDatabase.Conection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("delete from hoadon where sohd ='" + sohd + "'", conn);
            cmd.ExecuteNonQuery();
        }
        public void ThemHoaDon(string hoadon, string mahang, string diengiai,
                          double soluong, double dongia, double trigia, double khuyenmai)
        {
            SqlConnection conn = SQLDatabase.Conection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("insert into hoadon values ('" + hoadon + "','" + mahang + "'," + soluong.ToString() + "," + dongia.ToString() + "," + trigia.ToString() + "," + khuyenmai.ToString() + ",N'" + diengiai + "')", conn);
            cmd.ExecuteNonQuery();
        }
        public void SuaHoaDon(string shd, string sohd, string mahang, string diengiai, double soluong, double dongia, double trigia, double khuyenmai)
        {
            SqlConnection conn = SQLDatabase.Conection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("update hoadon set sohd='" + sohd + "',mahang='" + mahang + "',diengiai=N'" + diengiai + "',soluong='" + soluong.ToString() + "',dongia='" + dongia.ToString() + "',trigia='" + trigia.ToString() + "',khuyenmai='" + khuyenmai.ToString() + "'where sohd='" + shd + "'", conn);
            cmd.ExecuteNonQuery();
        }
    }
}
